﻿using System;
using System.Windows.Forms;
using FoundationClass;
using FoundationClass.Entity;

namespace P2MARY_INTERNET
{
    public partial class LoginForm : Telerik.WinControls.UI.RadForm
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        public User UserLogin { get; set; }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                UserLogin = SecurityHandler.LogIn(txtUserName.Text, txtPassword.Text);
            }
            catch (Exception ex)
            {
                lblValidate.Text = ex.Message;
                return;
            }

            if (UserLogin.Position == 0)
            {
                DialogResult = DialogResult.OK;
            }
            else if (UserLogin.Position == 1)
            {
                DialogResult = DialogResult.OK;
            }
            else 
                DialogResult = DialogResult.Cancel;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}
